package sparkcore.day7.lesson02

import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by Administrator on 2018/5/3.
  * RDD -> DataFrame
  */
case class People(var name:String,var age:Int)
object DataFrameReflection {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local").setAppName("test")
    val sc = new SparkContext(conf)

    val sqlContext = new SQLContext(sc)
    import sqlContext.implicits._
    val peopleRDD: RDD[People] = sc.textFile("D:\\1711班\\第十三天\\资料\\people.txt")
      .map(line => People(line.split(",")(0), line.split(",")(1).trim.toInt))
    val df = peopleRDD.toDF()
       df.createOrReplaceTempView("people")
    sqlContext.sql("select * from people").show()






  }

}
